package com.fast.fastenjoy.base.dao.sqltemplate.transformer;

import java.util.Date;

import com.fast.fastenjoy.base.utils.StringExUtils;

/**
 * 单个返回
 * @author chenliaohua
 *
 */
public class SingleSqlMapResultTransformer extends ResultTransformerEx{

	private static final long serialVersionUID = 8534418421969347442L;

	public static final SingleSqlMapResultTransformer INSTANCE = new SingleSqlMapResultTransformer(null);
	
	private SingleSqlMapResultTransformer(Class<?> entityClass) {
		super(entityClass);
	}

	public static boolean isSingleSqlMap(String entityClass){
		
		return StringExUtils.equalsIgnoreCase(entityClass, "int") || 
				StringExUtils.equalsIgnoreCase(entityClass, "string") || 
				StringExUtils.equalsIgnoreCase(entityClass, "long") || 
				StringExUtils.equalsIgnoreCase(entityClass, "date");
	}
	
	public static boolean isSingleSqlMap(Class<?> entityClass){
		
		return entityClass != null && 
				(entityClass.equals(int.class) || entityClass.equals(Integer.class) || 
						entityClass.equals(long.class) || entityClass.equals(Long.class) || 
						entityClass.equals(Date.class) || entityClass.equals(String.class) || 
						entityClass.equals(short.class) || entityClass.equals(Short.class) || 
						entityClass.equals(double.class) || entityClass.equals(Double.class));
	}
	
	public Object transformTuple(Object[] objs, String[] colNames) {
		
		if(objs == null || objs.length == 0 || objs[0] == null){
			return null;
		}
		
		Object obj = objs[0];
//		String str = String.valueOf(objs[0]);
//		
//		if(entityClass.equals(int.class)){
//			return Integer.valueOf(str);
//		}
//		
//		if(entityClass.equals(int.class)){
//			return Integer.valueOf(str);
//		}
//		
//		if(entityClass.equals(int.class)){
//			return Integer.valueOf(str);
//		}
//		
//		if(entityClass.equals(int.class)){
//			return Integer.valueOf(str);
//		}
		
		return obj;
	}

}
